package com.efast.dmom.mgmt.service.mes.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.mes.DeleteInBatchesFunctionBean;
import com.efast.dmom.mgmt.dao.mes.DeleteInBatchesFunctionDao;
import com.efast.dmom.mgmt.service.mes.DeleteInBatchesFunctionService;

@Service
public class DeleteInBatchesFunctionServiceImpl implements DeleteInBatchesFunctionService {

	@Autowired
	private DeleteInBatchesFunctionDao deleteInBatchesFunctionDao;
	
	@Override
	public void deleteInBatchesFunction(DeleteInBatchesFunctionBean deleteData) {
		if(deleteData.getIds() != null && deleteData.getIds().size() > 0) {
			deleteInBatchesFunctionDao.deleteInBatchesFunction(deleteData.getTableName(),deleteData.getFiledName(),deleteData.getIds());
		}
	}

	@Override
	public ResultBean validateAddAfterQualityData(Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true);
		String flag = (String)map.get("flag");
		Integer validateAddAfterQualityData = deleteInBatchesFunctionDao.validateAddAfterQualityData(map);
		if (flag.equals("edit")) {
			if (validateAddAfterQualityData != null && validateAddAfterQualityData >= 1 ) {
				resultBean.setSuccess(false);
				resultBean.setMessage("当前数据已存在！");
			}
		} else {
			if (validateAddAfterQualityData != null && validateAddAfterQualityData >0 ) {
				resultBean.setSuccess(false);
				resultBean.setMessage("当前数据已存在！");
			}
		}
		return resultBean;
	}

}
